import { _decorator, AudioSource, Component, Label, Node } from 'cc';
import { gameState } from './gameState';
const { ccclass, property } = _decorator;

@ccclass('audios')
export class audios extends Component {
    @property(Label) btn_sound_label:Label = null;
    audio_sound:AudioSource = null;
    start() {
        
    }

    update(deltaTime: number) {
        
    }
    init_bg_sound(){
        this.audio_sound = this.node.getComponent(AudioSource);
        this.on_off_sound();
    }

    private on_off_sound(){
        if(gameState.sound_state){
            this.btn_sound_label.string = '关闭音乐'
        }else{
            this.btn_sound_label.string = '开启音乐'
        }
        if(gameState.sound_state){
            this.audio_sound.play();
            this.audio_sound.loop = true;
        }else{
            this.audio_sound.stop();
            this.audio_sound.loop = false;
        }
    }

    stop_bg_sound(){
        this.audio_sound.stop();
    }

    click_sound(){
        gameState.sound_state =!gameState.sound_state;
        this.on_off_sound();
    }
}


